ima_t *ima_read(f,type)
FILE *f;
int type;
int ima_write(f,ima,type,ras_type)
FILE *f;
ima_t *ima;
int type,ras_type;
ima_t *ima_create(vsize,hsize,type)
int vsize,hsize,type;
int ima_destroy(ima)
ima_t *ima;
ima_t *ima_convert(ima,type)
ima_t *ima;
int type;
The image structure is defined as:
typedef struct
{
union
{
byte_t **b;
int **i;
double **d;
} data;
int vsize;
int hsize;
int depth;
colormap_t *colormap;
} ima_t;
The following image types are provided:
IMA_BIT, IMA_BYTE, IMA_INT, IMA_DOUBLE.
An additional type IMA_RAW can be used to force 'no conversion' for
the functions ima_convert, ima_read and ima_write.
ima_read reads an image from an opened file f. The file may be any SUN rasterfile or an unformatted square image, 1 byte/pixel, as used with the tutvis system. Memory required to store the image is allocated dynamically by ima_read. If the rasterfile contains a colormap, memory will be allocated and the colormap is read into the corresponding field of the image structure. If the file is not a rasterfile, ima_read will try to read a square tutvis image. If this also fails or an other error occurs, NULL is returned. Normally a pointer to the image structure is returned. ima_read will convert the read image to image type type. If type is IMA_RAW, the image is not converted. If the image data is read from a pipe, and it is not a rasterfile, ima_read will attempt to read a tutvis image of size 256*256.
ima_write writes an image to an opened file f. The parameter ras_type determines how the image is written. Currently available formats are: rasterfile standard (IMA_STANDARD), rasterfile run length coded (IMA_BYTE_ENCODED) and tutvis format (IMA_TUTVIS). Before writing the image, it is converted to image type type. If type is IMA_RAW, no conversion is done. Ima_write returns IMA_ERR if an error occurs during writing, normally it returns IMA_OK.
ima_create creates and initialises an image structure in memory of size vsize*hsize and of image type type. Sufficient memory is dynamically allocated to hold the image data and cleared to 0. The ima_colormap field is set to NULL. ima_create returns a pointer to the image structure, or NULL if an error occurs. ima_destroy releases all memory occupied by an image structure and it's image data. With image structures created with ima_point, ima_data or with ima_pr_ima for pixrects created with the pixrect function mem_point the image data memory is not released. ima_destroy returns IMA_OK (=0).
ima_convert converts an image to an image of image type type. If the conversion is succesful, a pointer to the resulting image is returned. On error NULL is returned. Memory required for the resulting image is dynamically allocated. Conversion to images of type IMA_BIT use thresholding at 128. Conversion from bit images result in levels 0 and 255. In conversion of double images the values are chopped of, not rounded. Overflow may occur in conversion from double to byte or int and from int to byte.
The following macro's are available to obtain information about the image size and type (stored in the underlying pixrect structure).
IMA_VSIZE(ima)
- number of rows of the image
IMA_HSIZE(ima)
- number of collumns of the image
IMA_TYPE(ima)
- image type
IMA_DEPTH(ima)
- depth of the image in bits/pixel
The following macro's are available for accessing image data:
IMA_BITDATA(ima)
- access bit image 1 byte at a time
IMA_BYTEDATA(ima)
- access image data byte wise
IMA_INTDATA(ima)
- access image data as integers
IMA_DOUBLEDATA(ima)
- access image data as doubles